#include <stdio.h>
#include <dlfcn.h> // dlopen, dlerror, dlsym, dlclose

typedef int (*FUN_ADD)(int, int);
typedef int (*FUN_PRINT)(const char*);

int main(void)
{
    FUN_ADD fun_add;
    FUN_PRINT fun_print;

    void *handle = dlopen("libtest.so", RTLD_LAZY);
    if (!handle)
    {
        printf("dlopen failed - %s \r\n", dlerror());
        return -1;
    }

    fun_add = (FUN_ADD)dlsym(handle, "fun_add");
    if (fun_add)
        printf("fun_add(1, 2) = %d \r\n", fun_add(1, 2));
    else
        printf("dlsym fun_add failed \r\n");

    fun_print = (FUN_PRINT)dlsym(handle, "fun_print");
    if (fun_print)
        fun_print((const char*)"fun_print: abc \r\n");
    else
        printf("dlsym fun_add failed \r\n");

    dlclose(handle);
    return 0;
}
